/* CS 321 FALL 2014 Professor Pettit Temperature Control Impementation
 * 
 * Jung Joo
 * Ben Richards
 * Don Tran
 * Phil Shin
 * Anuraag Mattapally
 * 
 * Version control was maintained through GitHub
 * 
 * */

public class TempControl{
  public static Temperature desiredTemp;
  private static Temperature currentTemp;
  public AC myAC;
  public PriHeat myHeater;
  public SecHeat mySecHeater;
  public Fan myFan;
  public String modes;

  public TempControl(){
    this.myAC = new AC();
    this.myHeater = new PriHeat();
    this.mySecHeater = new SecHeat();
    this.myFan = new Fan();
    desiredTemp=new Temperature();
    currentTemp=new Temperature();
  }

  public void setMode(String mode){
    modes=mode;
    
    if (modes.equals("FanOnly")){
      myFan.on();
    }
    else if(modes.equals("Off")){
      myFan.off();
    }
    //In a complete real life implementation this condition would be repeating, continually checking the temperature to 
    //adjust whether or not the AC runs.  However, for unit testing purposes (since this is not a concurrent program)
    //the while loop has been commented out (since we cannot change the mode while it runs). The while loop is critical
    //in a complete implementation as it allows the tempcontrol to remain in the cooling state indefinitely.
    else if(modes.equals("AC")){
      myFan.on();
      double monitor;
      //This next line is for a full implementation where the mode can be changed while the program runs. Once a new
      //mode is set from the thermostat, this while statement will become false, and a new set mode process will 
      //commence based on the new mode. 
      //while (modes.equals("AC")){
        monitor=monitorTemp();
        if (monitor>0.0){
          myAC.off();
        }
        else if (monitor<=0.0){
          myAC.on();
        }
      }
    
    //In a complete real life implementation this condition would be repeating, continually checking the temperature to 
    //adjust whether or not a heater runs.  However, for unit testing purposes (since this is not a concurrent program)
    //the while loop has been commented out (since we cannot change the mode while it runs). The while loop is critical
    //in a complete implementation as it allows the tempcontrol to remain in the heating state indefinitely. 
    else if(modes.equals("Heat")){
      myFan.on();
      double monitor;
      //This next line is for a full implementation where the mode can be changed while the program runs.Once a new
      //mode is set from the thermostat, this while statement will become false, and a new set mode process will 
      //commence based on the new mode. 
      //while(modes.equals("Heat")){
        monitor=monitorTemp();
        if (monitor>0.0 & monitor<10.0){
          myHeater.on();
        }
        else if(monitor>=10.0){
          myHeater.on();
          mySecHeater.on();
        }
        else if(monitor<=0.0){
          myHeater.off();
          mySecHeater.off();
        }
    }
    else{
      System.out.println("Badmode!");
    }
  }
  public double monitorTemp(){
    return desiredTemp.get()-currentTemp.get();
  };
  
}

class Temperature{
  double x;
  
  public Temperature(){
    x=7.3;
  }
  public void set(double v){
    x=v;
  }
  public double get(){
    return x;
  }
}

class Thermostat{
  private static Temperature desiredTemp;
  private static Temperature currentTemp;
  
  public Thermostat(){
    desiredTemp=new Temperature();
    desiredTemp.set(8.4f);
    currentTemp=new Temperature();
  }
  
  public void setdesiredTemp(double x){
    desiredTemp.set(x);
  }
}

class AC{
  private Boolean currentMode;
  private Long physicalAddress;
  
  public AC(){
    currentMode=false;
    physicalAddress=213129L;
  }
  
  public void on(){
    currentMode=true;
  }
  public void off(){
    currentMode=false;
  }
  public Boolean getMode(){
    return this.currentMode;
  }
}

class PriHeat{
  private Boolean currentMode;
  private Long physicalAddress;
  
  public PriHeat(){
    currentMode=false;
    physicalAddress=23427L;
  }
  
  public void on(){
    currentMode=true;
  }
  public void off(){
    currentMode=false;
  } 
   public Boolean getMode(){
    return this.currentMode;
  } 
}

class SecHeat{
  private Boolean currentMode;
  private Long physicalAddress;
  
  public SecHeat(){
    currentMode=false;
    physicalAddress=22326L;
  }
  
  public void on(){
    currentMode=true;
  }
  public void off(){
    currentMode=false;
  } 
   public Boolean getMode(){
    return this.currentMode;
  } 
}

class Fan{
  private Boolean currentMode;
  private Long physicalAddress;
  
  public Fan(){
    currentMode=false;
    physicalAddress=22323L;
  }
  
  public void on(){
    currentMode=true;
  }
  public void off(){
    currentMode=false;
  }
  public Boolean getMode(){
    return this.currentMode;
  } 
}
  
  